<?php

namespace myshop\test\controller;


use longhu\base\AdminBaseController;
use longhu\library\SimpleMQProduce;
use longhu\library\WechatService;
use longhu\MyResponse;
use myshop\common\model\AdminApiLog;
use myshop\system\model\AdminLoginLog;
use think\annotation\route\Route;
use think\facade\Cache;
use think\facade\Db;
use think\response\Json;

class Test extends AdminBaseController
{
//    public function __construct(AdminBaseRequest $request)
//    {
//        $this->request = $request;
//    }

    public function index()
    {

       Cache::store('redis')->tag('admin:')->set('username','longhu');
        return MyResponse::success('ok');
    }

    public function error()
    {
        return MyResponse::fail('','10001');
    }

    /**
     * @return Json
     */
    #[Route("GET","test/create")]
    public function create()
    {
//        $res = Db::connect('mongo')->name('admin_api_log')->insert([
//            'admin_id'=>2,
//            'api_method'=>'get',
//            'route'=>'/sys/auth/login',
//            'params'=>json_encode([
//                'username'=>'admin',
//                'passwrod'=>'123456',
//            ]),
//            'api_status'=>1,
//            'create_at'=>time(),
//        ]);
        $data = [
            'admin_id'=>3,
            'title'=>'登录',
            'api_method'=>'post',
            'route'=>'/sys/auth/login',
            'admin_ip'=>'127.0.0.1',
            'method'=>'post',
            'params'=>json_encode([
                'username'=>'admin',
                'passwrod'=>'123456',
            ]),
            'status'=>1,
            'create_at'=>time(),
        ];
        $mqService = new SimpleMQProduce();
        $mqService->fanout('topic',$data);
        return MyResponse::success($data);
    }

    #[Route('GET','test/wechat')]
    public function getWechat()
    {
        $server = WechatService::create()->getApplication();
//        $server->with(function($message, \Closure $next) {
//            // 你的自定义逻辑
//            echo 123;
//        });

        return $server->serve();

    }

}